import React from 'react';
import sha256 from 'crypto-js/sha256';
import { go_ } from './util';
import { Link } from '@mui/material';

export default function Home() {
    function* gen(x) {
        let y = yield x * x
        let z = yield y ? y * 3 : x * 100
        return z || 89
    }

    let a = gen(2)
    // for (let x in a) {
    //     console.log(x)
    // }
    console.log(a.next())
    console.log(a.next())
    console.log(a.next())

    console.log('fc.getInfo()')

    let person = new Person('kiven', 18)
    console.log(person)

    let user = new User(23)
    console.log(user)
    user.toSleep()
    User.todo()

    function jiami() {
        console.log('https://www.npmjs.com/package/crypto-js')
        console.log(sha256('message').toString())
    }

    return (
        <>
            <h2>Home</h2>
            <div><a href={go_('/demos/rxjs')}>rxjs</a></div>
            <Link
                component="button"
                variant="body2"
                onClick={jiami}
            >
                crypto
            </Link>
        </>
    )
}

function Person(name, age) {
    this.name = name
    this.age = age
    this.say = function (word) {
        return 'What is ' + word
    }
}

Person.todo = function () {
    console.log('todo')
}

class User {
    // 属性和构造方法
    userName = 'kiven'

    constructor(age) {
        this.age = age
        this.sex = 0
    }

    // 私有变量和私有方法
    #sleep = 'sleep 10'

    #nn = function () {
        console.log('nn ' + this.#sleep)
    }

    toSleep() {
        console.log('toSleep ' + this.#sleep)
    }

    // 静态属性和静态构造方法
    static pp = 'px'
    static todo = function () {
        console.log('User todo ')
    }
}

